package com.zdxlz.mongodbDemo.service;

import com.zdxlz.mongodbDemo.pojo.Comment;
import com.zdxlz.mongodbDemo.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

@Service
public class CommentService {
    private final CommentRepository repository;

    @Autowired
    public CommentService(CommentRepository repository) {
        this.repository = repository;
    }

    public Comment findById(String id) {
        return repository.findById(id).get();
    }

    public Page<Comment> findPage(int pageNum, int pageSize) {
        return repository.findAll(PageRequest.of(pageNum-1, pageSize));
    }

    public Comment save(Comment comment) {
        return repository.save(comment);
    }

    public Comment update(Comment comment) {
        return repository.save(comment);
    }

    public void deleteById(String id) {
        repository.deleteById(id);
    }
}
